// eslint-disable-next-line strict
const Service = require('egg').Service;

class UserService extends Service {
  async createUser(params) {
    console.log(params);
    const { app } = this;
    try {
      const result = await app.mysql.insert('user', params);
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async getUser(email) {
    if (!email) {
      console.log('email 必须有值');
      return null;
    }
    try {
      const result = await this.app.mysql.get('user', { email });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async getUserInfo(nickname) {
    if (!nickname) {
      console.log('username 必须有值');
      return null;
    }
    try {
      const result = await this.app.mysql.get('user', { nickname });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async login(psw) {
    if (!psw) {
      console.log('没有密码');
      return null;
    }
    try {
      const result = await this.app.mysql.get('user', { password: psw });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
}

module.exports = UserService;
